home *** CD-ROM | disk | FTP | other *** search
/ hornet.scene.org / hornet.scene.org FTP 11-25-2012.zip / hornet.scene.org FTP 11-25-2012 / code / library / i3ddemo2.exe / I3DKIT.H < prev    next >
C/C++ Source or Header  |  1994-04-05  |  10KB  |  292 lines

  1. //***************************************************************************
  2. //*                                                                         *
  3. //* Interactive 3D Tool Kit I3D v2.0                                        *
  4. //*                                                                         *
  5. //* I3D API                                                                 *
  6. //*                                                                         *
  7. //* (c) 1993-94 Jim O'Keane                                                 *
  8. //* All Rights Reserved Worldwide                                           *
  9. //*                                                                         *
  10. //***************************************************************************
  11.  
  12. #ifndef _I3DKIT_H
  13.  
  14. #define _I3DKIT_H 1
  15.  
  16. // Simple macros to facilitate global vars in .h files
  17. // Define MAIN in only one file before #includes.
  18. #ifndef MAIN
  19. #define GLOBAL extern
  20. #else
  21. #define GLOBAL
  22. #endif
  23.  
  24. // MS Windows-like types
  25. #ifndef __WINDOWS_H
  26. typedef unsigned char     BYTE;
  27. typedef unsigned short    WORD;
  28. typedef unsigned long     DWORD;
  29. typedef short            BOOL;
  30. #define FALSE            0
  31. #define TRUE            1
  32.  
  33. typedef struct
  34.   {
  35.   short x;
  36.   short y;
  37.   } POINT;
  38.  
  39. #endif
  40.  
  41.  
  42. #ifndef FAR
  43. #define FAR far
  44. #endif
  45.  
  46. #ifndef NEAR
  47. #define NEAR near
  48. #endif
  49.  
  50. #ifndef PASCAL
  51. #define PASCAL pascal
  52. #endif
  53.  
  54. #ifdef __FLAT__
  55. // If 32 bit compiler, dump the "far", "near" and the "pascal"
  56.  
  57. #undef  FAR
  58. #define FAR  
  59.  
  60. #undef  NEAR
  61. #define NEAR 
  62.  
  63. #undef  PASCAL
  64. #define PASCAL
  65.  
  66. #endif
  67.  
  68. // Maps are always 128 by 128 blocks. (128 x 128 x 2 = 32K Bytes)
  69. // If you need a smaller map, just don't use whole array.
  70. // The map contains indexes into the block definition array.
  71. #define MAP_WIDTH  128
  72. #define MAP_HEIGHT 128
  73.  
  74. // Automapping flags
  75. #define AUTOMAP_SEEN   1  // block has been seen by the viewer (automap)
  76.  
  77. // Map array type
  78. typedef short MAPTYPE[MAP_WIDTH][MAP_HEIGHT];
  79.  
  80. // the VGA palette data structure
  81. typedef BYTE DACPAL256[256][3];
  82.  
  83. // size of map cell 256x256x256 units (high byte of world coords is map coord)
  84. #define BLOCK_SIZE     256
  85. // mask is used to find position inside a block
  86. #define BLOCK_MASK     255
  87. // shift is used to find the map coords from world coords
  88. #define BLOCK_SHIFT    8
  89.  
  90. // Block shape types 
  91. #define BLOCK_OPEN     0  // block is just floor & ceiling
  92. #define BLOCK_CUBE     1  // block is a cube
  93. #define BLOCK_HORZ     2  // block is a horizontal (EW) divider
  94. #define BLOCK_VERT     3  // block is a vertical (NS) divider
  95. #define BLOCK_ACTOR    4  // block is an actor or prop
  96. #define BLOCK_DIAG1    5  // block is a diagonal wall
  97. #define BLOCK_DIAG2    6  // block is a diagonal wall
  98.  
  99. // Bit flags used by I3D Engine
  100. #define BLOCK_TRANS      1   // block is transparent
  101. #define BLOCK_WALL       2   // block is an impassable
  102. #define BLOCK_BI         4   // Thing is bilaterally symmetric, saves views
  103.  
  104. // definition of a block
  105. typedef struct tag_block
  106. {
  107.   short shape;     // type of shape
  108.   short flags;     // bit flags
  109.  
  110.   short light;     // "light" level 0 = normal, < 0 "darker", > 0 "lighter"
  111.    
  112.   short twidth;    // texture map width (32,64,128)
  113.   short twidth_shift; // texture map width in shift (5,6,7)
  114.   short theight;   // texture map height
  115.   short tsize;     // texture map size in bytes
  116.  
  117.   short x_offset;  // positional offset (+/- 1/2 BLOCK_SIZE)
  118.   short y_offset;  // used to animate blocks and things
  119.  
  120.   short n_wall;    // wall panel to show (-1 = none)
  121.   short e_wall;    // wall panel to show (-1 = none)
  122.   short s_wall;    // wall panel to show (-1 = none)
  123.   short w_wall;    // wall panel to show (-1 = none)
  124.  
  125.   short ceil;      // ceiling panel to show - must be (twidth x twidth)
  126.   short floor;     // floor panel to show  - must be (twidth x twidth)
  127.  
  128.   short user1;     // user defined 
  129.   short user2;
  130.   short user3;
  131.   short user4;
  132. } BLOCK;
  133.  
  134. // if a block is an actor or prop, cast the block struct to this:
  135. typedef struct tag_thing 
  136. {
  137.   short shape;     // type of shape
  138.   short flags;     // bit flags
  139.  
  140.   short light;     // "light" level 0 = normal, < 0 darker, > 0 lighter
  141.   
  142.   short twidth;    // texture map width (32,64,128)
  143.   short twidth_shift; // texture map width in shift (5,6,7)
  144.   short theight;   // texture map height
  145.   short tsize;     // texture map size in bytes
  146.  
  147.   short x_offset;  // positional offset +/- 1/2 BLOCK_SIZE
  148.   short y_offset;  // used to animate blocks and things
  149.  
  150.   short panel;     // base panel to show (-1 = none)
  151.   short block;     // what background block is at this location
  152.   short views;     // how many directions give different views?
  153.   short heading;   // direction facing
  154.  
  155.   short res1;
  156.   short res2;
  157.  
  158.   short user1;     // user defined 
  159.   short user2;
  160.   short user3;
  161.   short user4;
  162. } THING;
  163.  
  164. // standard image operator macros
  165. #define IMAGE_SIZE256(width,height) ((long)(width)*(height))
  166.  
  167. // calc offset into image byte array for a pixel at (x,y)
  168. #define PIXPOS(x,y,width) (((y)*(width))+(x))
  169.  
  170. // handy macros
  171. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  172. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  173. #define SIGN(x)  (((x) < 0) ? -1 : (((x) > 0) ? 1 : 0))
  174. #define ABS(x) ((x)<0 ? -(x):(x))
  175.  
  176. // Prototypes ////////////////////////////////////////////////////
  177.  
  178. #if defined ( __cplusplus )
  179.   extern "C" {
  180. #endif
  181.  
  182. // Quicky integer math functions. High speed, low accuracy.
  183. short FAR q_sin( short angle );
  184. short FAR q_cos( short angle );
  185. // rotate point (x,y) about center (cx,cy) by angle 
  186. void  FAR rotate(short *x, short *y, short cx, short cy, short angle);
  187.  
  188. // I3D functions ////////////////////////////
  189.  
  190. // Tell the I3D engine what map to use. I3D keeps a copy of
  191. // this pointer, so you can change the map on the fly.
  192. // If the automap_ptr is NULL, no auto-mapping is done.
  193.  
  194. BOOL FAR i3d_set_map(MAPTYPE *map_ptr,MAPTYPE *automap_ptr);
  195.  
  196. // Tell the I3D engine about the texture map panels. I3D keeps a copy of
  197. // the pointer to the panel list, so you can change the texture maps on
  198. // the fly.
  199.  
  200. BOOL FAR i3d_set_panels(short num_panels, BYTE **panel_list);
  201.  
  202. // Tell the I3D engine about you block definition list. I3D keeps a copy
  203. // of the pointer to the block list, so you can change the block definitions
  204. // on the fly.
  205.                       
  206. BOOL FAR i3d_set_blocks(short num_blocks, BLOCK *block_list);
  207.  
  208. // Tell the I3D engine to use a solid color for floors and ceilings. If set
  209. // to zero, uses texture mapped floors and/or ceilings. If set to -1, then
  210. // no drawing is done, caller is expected to fill POV buffer with backdrop.
  211.  
  212. BOOL FAR i3d_set_floor_ceil(short floor_col, short ceil_col);
  213.  
  214. // Tell the I3D engine to use a set of Palette Indirection Tables
  215. // I3D keeps a copy of the pointer to the paltable list, so you can change
  216. // the actual tables on the fly. 
  217. //
  218. // max_levels is the table number which lighting effects fade to at the
  219. // far end. Shift is how far to right shift the distance to determine
  220. // the light level.
  221.  
  222. // For example, I want each light level to be 1 block wide (256) so my shift
  223. // is 8. I set max_levels to be 16, and I can see at most 16 blocks
  224. // away before it is all darkness (or solid color).
  225.  
  226. // Set paltables_ptr to NULL and max_levels to 0 for no lighting effects.
  227. // (default)
  228.  
  229. void FAR i3d_set_lighting(BYTE **paltables_ptr,
  230.                                  short max_levels, short shift);
  231.  
  232. // Calculate the fade tables from 0% to 100% over a series of steps
  233.  
  234. void FAR i3d_calc_paltables(BYTE **paltable_ptr,DACPAL256 *pal,
  235.                             short max_levels, short max_color);
  236.  
  237. // Tell the I3D engine the dimensions of the window buffer it uses, and
  238. // the width of a line in bytes.
  239.  
  240. BOOL  FAR i3d_set_window_buffer(short width, short height,
  241.                                 short line_width,
  242.                                 BYTE *buf);
  243.  
  244. // Shutdown the I3D Engine - free memory buffers
  245.  
  246. void FAR i3d_shutdown(void);
  247.  
  248. // Ask I3D to create a frame in the window buffer.
  249.  
  250. // INPUT:
  251. // (s_x,s_y) = viewer eye position
  252. // horizon   = where in POV buffer place horizon - makes head tilt up/down
  253. // eye_level = how high is eye? valid range 1 to (BLOCK_SIZE-1)
  254. // scan_width, scan_height = vary these for aspect ratio and field of view
  255. //                           (normally the same as POV window width)
  256. // heading   = which way is viewer looking
  257.  
  258. void FAR i3d_view_scan256(short s_x, short s_y,
  259.                           short horizon, short eye_level,
  260.                           long  scan_width, long scan_height,
  261.                           short heading);
  262.  
  263. // Ask I3D to tell you what is hit at a particular point in the window buffer.
  264.  
  265. // INPUT:
  266. // (s_x,s_y) = viewer eye position
  267. // horizon   = where in POV buffer place horizon - makes head tilt up/down
  268. // eye_level = how high is eye? valid range 1 to (BLOCK_SIZE-1)
  269. // scan_width, scan_height = vary these for aspect ratio and field of view
  270. //                           (normally the same as POV window width)
  271. // heading   = which way is viewer looking
  272.  
  273. // click_x,click_y = coords in POV buffer they user hit
  274.  
  275. // OUTPUT:
  276. // h_x,h_y,h_z = position in world space point hit
  277. // block_id    = index in block list of block hit
  278. // panel_u,panel_v = position in texture map hit
  279.  
  280. void FAR i3d_hit_scan256(short s_x, short s_y,
  281.                          short horizon, short eye_level,
  282.                          long  scan_width, long scan_height,
  283.                          short heading,
  284.                          short click_x, short click_y,
  285.                          short *h_x, short *h_y, short *h_z,
  286.                          short *block_id, short *panel_u, short *panel_v);
  287. #if defined ( __cplusplus )
  288.   }
  289. #endif
  290.  
  291. #endif
  292.